import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2023-10-30
 * Time:14:58
 * Text：
 */
public class Text1 {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String t=in.nextLine();
            String s=in.nextLine();
            System.out.println(match(t,s));
        }
    }
    public static boolean match(String t,String s){
        char[] ct=t.toCharArray();
        char[] cs=s.toCharArray();
        int lt=ct.length;
        int ls=cs.length;
        boolean[][] dp=new boolean[ls+1][lt+1];
        dp[0][0]=true;
        for(int i=0;i<=ls;i++){
            for(int j=1;j<=lt;j++){
                if(ct[j-1]=='*'){
                    if(i==0){
                        dp[i][j]=dp[i][j-1];
                    }else{
                        if(cs[i-1]=='.'|| (cs[i-1]>='A'&&cs[i-1]<='Z') ||
                                (cs[i-1]>='a'&&cs[i-1]<='z') ||
                                (cs[i-1]>='0'&&cs[i-1]<='9') ){
                            dp[i][j]=dp[i-1][j] || dp[i][j-1];
                        }
                    }
                }else{
                    if(i>0 && defs(ct[j-1],cs[i-1])){
                        dp[i][j]=dp[i-1][j-1];                    }
                }
            }
        }
        return  dp[ls][lt];
    }

    public static boolean defs(char t,char s){
        if(t=='?') return true;
        if(t>='a'&&t<='z'){
            t=(char)(t-'a'+'A');
        }
        if(s>='a'&&s<='z'){
            s=(char)(s-'a'+'A');
        }
        return s==t;
    }


}